package com.loop.collection.list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class ListDemo {
    public static void main(String[] args) {
        /*List<String> list = new ArrayList();
        list.add("a");
        list.add(0,"first");
        System.out.println(list);
        list.set(0,"1");
        System.out.println(list);

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }*/

        /*list.set(3,"c");
        System.out.println(list);//IndexOutOfBoundsException*/
        //System.out.println(list);
        /*for (String str:list) {
            if ("1".equals(str)){
                list.add("jhaa");
            }
        }
        System.out.println(list);*/

        /*Iterator<String> iterator = list.iterator();
        while(iterator.hasNext()){
            String str = iterator.next();
            if ("1".equals(str)){
                //list.add("hahah");
            }
        }
        System.out.println(list);*/
        practice();
    }

    public static void practice(){
        List<String> list = new ArrayList();
        list.add("ok");
        list.add("java");
        list.add("hello");
        list.add("world");

        /*ListIterator<String> iterator = list.listIterator();
        while (iterator.hasNext()){
            String str = iterator.next();
            if ("hello".equals(str)){
                //list.add("sss");
                iterator.add("sss");
            }
        }
        System.out.println(list);*/

        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).equals("hello")){
                list.add(0,"hahah");
                i++;
            }
        }
        System.out.println(list);
    }
}
